{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# THE CODE IS IN MY GITHUB!!!\n",
    "Go and checkout my github if you want the to_candle file!\n",
    "## https://github.com/kecoma1/Trading_BOT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import to_candle"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Candle dataframe\n",
    "This dataframe is obtained through the from_tick_to_candle function. The dataframe contains the following columns:\n",
    "* **TIME-UTC**: UTC-TIME since epoch in seconds.\n",
    "* **OPEN**: Open price of that candle.\n",
    "* **CLOSE**: Close price of the candle.\n",
    "* **HIGH**: Highest price of the candle.\n",
    "* **LOW**: Lowest price of the candle."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TIME-UTC</th>\n",
       "      <th>OPEN</th>\n",
       "      <th>CLOSE</th>\n",
       "      <th>HIGH</th>\n",
       "      <th>LOW</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.632953e+09</td>\n",
       "      <td>1.15982</td>\n",
       "      <td>1.15968</td>\n",
       "      <td>1.16015</td>\n",
       "      <td>1.15939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.632954e+09</td>\n",
       "      <td>1.15968</td>\n",
       "      <td>1.15983</td>\n",
       "      <td>1.15990</td>\n",
       "      <td>1.15964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.632955e+09</td>\n",
       "      <td>1.15983</td>\n",
       "      <td>1.15966</td>\n",
       "      <td>1.15983</td>\n",
       "      <td>1.15964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.632956e+09</td>\n",
       "      <td>1.15966</td>\n",
       "      <td>1.15980</td>\n",
       "      <td>1.15997</td>\n",
       "      <td>1.15966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.632956e+09</td>\n",
       "      <td>1.15980</td>\n",
       "      <td>1.15975</td>\n",
       "      <td>1.15990</td>\n",
       "      <td>1.15966</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       TIME-UTC     OPEN    CLOSE     HIGH      LOW\n",
       "0  1.632953e+09  1.15982  1.15968  1.16015  1.15939\n",
       "1  1.632954e+09  1.15968  1.15983  1.15990  1.15964\n",
       "2  1.632955e+09  1.15983  1.15966  1.15983  1.15964\n",
       "3  1.632956e+09  1.15966  1.15980  1.15997  1.15966\n",
       "4  1.632956e+09  1.15980  1.15975  1.15990  1.15966"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "candle_df = to_candle.from_tick_to_candle(\"EURUSD.csv\", 15*60)\n",
    "candle_df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Technical analysis library - ta.trends.MACD\n",
    "**pip install ta**\n",
    "\n",
    "Using the *ta* library we are going to load the MACD information of the current dataframe using the *close column*."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ta.trend import MACD\n",
    "macd_object = MACD(candle_df[\"CLOSE\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Computing the MACD line and the SIGNAL line.\n",
    "\n",
    "### MACD Line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "178    0.000187\n",
       "179    0.000190\n",
       "180    0.000180\n",
       "181    0.000196\n",
       "182    0.000199\n",
       "Name: MACD_12_26, dtype: float64"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "macd_line = macd_object.macd()\n",
    "macd_line.tail(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### SIGNAL Line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "178    0.000234\n",
       "179    0.000225\n",
       "180    0.000216\n",
       "181    0.000212\n",
       "182    0.000210\n",
       "Name: MACD_sign_12_26, dtype: float64"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "signal_line = macd_object.macd_signal()\n",
    "signal_line.tail(5)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
